package com.hzhh123.config;

import com.hzhh123.job.SimpleJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzJobConfig {
    @Value("${schedule.task.simple}")
    private String testScheduleCron;


    @Bean
    public JobDetail simpleJobDetail(){
        return JobBuilder.newJob(SimpleJob.class).withIdentity("simpleJobDetail").storeDurably().build();
    }

    @Bean
    public Trigger simpleTrigger(){
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(testScheduleCron);
        return TriggerBuilder.newTrigger().forJob(simpleJobDetail())
                .withIdentity("simpleTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
